package com.ar.network;

import android.app.AlertDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


/**
 * The Class NetworkUtility.
 * @author anh
 */
public class NetworkUtility {
	
	public static final String GET_QUIZS_URL = "getquizs";
	public static final String GET_QUIZS_TAG = "GET_QUIZS";
	public static final String ONLOAD_DIFFICULT = "on_load_difficult";
	public static final String PHONE_NUMBER = "phone_number";
	public static final String IMEI = "IMEI";
	public static final String REQUEST_LOAD = "request_load";
	public static final String CATEGORY_ID = "category_id";
	public static final String REST_CATEGORY_ID = "categoryId";
	public static final String DIFFICULT_ID = "difficult_id";
	public static final String REST_DIFFICULT_ID = "diffId";
	public static final String CATEGORY_TYPE = "category_type";
	public static final int DEFAULT_TIME_OUT = 5000;
	public static final String ID = "id";
	public static final String CATEGORY = "category_code";
	public static final String QUESTION = "top_content";
	public static final String ANSWERS = "answers";
	public static final String IMAGE_URL = "image_url";
	public static final String IMAGE_DESCRIPTION = "bottom_content";
	public static final String TYPE = "type";
	public static final String POINT = "point";
	public static final String MARK = "total_point";
	public static final String RESULTS = "results";
	public static final String CHECK = "check";
	public static final String CHOOSE = "choose";
	public static final String TRUE_ANSWERS = "true_answer";
	public static final String DATA = "data";
	public static final String TIME = "time";
	public static final String HANDLE = "handle";
	public static final String ONLOGIN = "on_login";
	public static final String ONLOAD = "on_load";
	public static final String ONERROR = "on_error";
	public static final String ONCHECK = "on_check";
	public static final String ERROR_MESSAGE = "message";
	public static final String ERROR_CODE = "errorCode";
	
	
	//contest
	public static String API_URL = "http://117.7.70.208:8081/Services/Index";
	public static final String LOGIN_URL = "login";
	public static final String LOGIN_FB_URR = "login_fb";
	public static final String REGISTER_URL = "register";
	public static final String UPDATE_INFO_URL = "update_info";
	public static final String UPLOAD_RECORD_URL = "register";
	public static final String SUBMIT = "submit";
	
	public final static String HANDLE_UPDATE_INFO = "update_info";
	public final static String HANDLE_SAVE_DATA = "save_data";
	public final static String HANDLE_LOAD_SAVED_DATA = "load_saved_data";
	public final static String HANDLE_SUBMIT_CONTEST = "submit_contest";
	public final static String HANDLE_REGISTER = "on_register";
	public final static String HANDLE_LOGIN = "on_login";
	public final static String HANDLE_LOAD_SURVEY = "on_load_survey";
	public final static String HANDLE_LOAD_QUESTION = "on_load_question";
	
	
	public static final String APP_ID = "app_id";
	public static final String FACEBOOK = "2";
	public static final String NORMAL = "1";
	public static final String USER_INFOR = "user_infor";
	public static final String USER_INFO = "user_info";
	
	public static final String CONTEST_ID = "contest_id";
	public static final String UPLOAD_TIME = "time";
	public static final String UPLOAD_DATA = "data";
	public static final String QUESTION_ID = "question_id";
	public static final String ANSWER  = "ANSWER";
	
	
	
	public static final String USER_ID = "user_id";
	public static final String FULL_NAME = "full_name";
	public static final String PASSWORDS = "password";
	public static final String NAME = "name";
	public static final String PHONE = "phone";
	public static final String EMAIL = "email";
	public static final String BIRTH_DAY = "birth_day";
	public static final String BIRTHDAY = "birthday";
	public static final String ADDRESS = "address";
	public static final String CHIDOAN = "chidoan";
	public static final String AREA_ID = "area_id";
	
	public static final String QUESTIONID = "QuestionID";
	public static final String ANSWERID = "AnswerID";
	public static final String ANSWERTEXT = "AnswerText";
	public static final String ANSWERTYPE = "AnswerType";
	public static final String STATUS = "Status";
	
	//contest

	/**
	 * Instantiates a new network utility object.
	 */
	public NetworkUtility() {
		
	}
	
	/**
	 * Check the network state.
	 *
	 * @param context the context to check network on
	 * @return true, if has usable network
	 */
	public static boolean checkNetworkState(Context context){
		ConnectivityManager conMgr =  (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo i = conMgr.getActiveNetworkInfo();
		  if (i == null)
		    return false;
		  if (!i.isConnected())
		    return false;
		  if (!i.isAvailable())
		    return false;
		return true;
	}
	
	/**
	 * Show a dialog which inform no Internet connection.
	 *
	 * @param context the context to show this dialog on
	 */
	public static void showNoNetworkDialog(Context context){
		AlertDialog.Builder restartAlertBuilder = new AlertDialog.Builder(context);
		restartAlertBuilder.setTitle("Không có kết nối mạng");
		restartAlertBuilder.setMessage("Vui lòng bật kết nối internet");
		restartAlertBuilder.setCancelable(false);
		restartAlertBuilder.setPositiveButton("Ok", null);
		
		AlertDialog restartAlertDialog = restartAlertBuilder.create();
		restartAlertDialog.show();
	}
	
	/**
	 * Show a dialog which inform the connection attempt reached it time out.
	 *
	 * @param context the context to show this dialog on
	 */
	public static void showTimeOutDialog(Context context){
		AlertDialog.Builder restartAlertBuilder = new AlertDialog.Builder(context);
		restartAlertBuilder.setTitle("Kết nối lỗi");
		restartAlertBuilder.setMessage("Không thể kết nối với server, vui lòng thử lại");
		restartAlertBuilder.setCancelable(false);
		restartAlertBuilder.setPositiveButton("Ok", null);
		
		AlertDialog restartAlertDialog = restartAlertBuilder.create();
		restartAlertDialog.show();
		
	}
	
	public static void showDialog(Context context, String title, String message){
		AlertDialog.Builder restartAlertBuilder = new AlertDialog.Builder(context);
		restartAlertBuilder.setTitle(title);
		restartAlertBuilder.setMessage(message);
		restartAlertBuilder.setCancelable(false);
		restartAlertBuilder.setPositiveButton("Ok", null);
		AlertDialog restartAlertDialog = restartAlertBuilder.create();
		restartAlertDialog.show();
		
	}

}
